<!--
  - create_createaccount.php
  - v0.01
  - 2/1/2011 
  -
  - This source code calls the InsertNewAnalysis() method which determines if
  -	the parameters are inserted to the database correctly. This redirects to a
  -	success page if the insertion is successful, else, it will return to the
  - create analysis page, generating an error.
  -->
<?php 
  session_start();
	require("libraries/SampleDetailLib.php");
	require("libraries/SampleEntryLib.php");
	
	$casl_no_year = $_POST['year'];
	$casl_no_sample = $_POST['samplestart'];
	$samplecount = $_POST['samplecount'];
	$PreparedBy = $_SESSION['name'];
	$ClientName =  $_POST['ClientName'];
	$ClientCompany =  $_POST['ClientCompany'];
	$ClientAddress =  $_POST['ClientAddress'];
	$ClientFax =  $_POST['ClientFax'];
	$ClientTel =  $_POST['ClientTel'];
	$ClientEmail =  $_POST['ClientEmail'];
	$ClientCell =  $_POST['ClientCell'];
	
	echo $samplecount;
	/*Insert into the new analysis into the database.*/
	$create = InsertNewSampleDetail($ClientName, $ClientCompany, $ClientAddress,
			$ClientFax, $ClientTel, $ClientEmail, $ClientCell, $PreparedBy, 
			"casl", "localhost",
			"createanalysis","createanalysis","sample_details");
	
	/*Check if the analysis was inserted or not.*/
	if($create != FALSE){
		echo "SUCCESS".$create;
		for($i = 0; $i  < $samplecount; $i++){
			InsertNewSampleEntry($casl_no_year,((int)$casl_no_sample+$i),"","","","","","","","",
			"","",$create,"casl","localhost","createanalysis","createanalysis","sample_entry");
		}
		$_SESSION['sample_key'] = $create;
		header("Location:EditSampleEntry.php");
	}else{
		echo '<script type= "text/javascript"> alert("An error has occured");</script>';
//		header("Location: CreateSampleEntry.php?error=true");
	}
?>